﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace YTV.MUpL
{
    class FTP
    {
        private bool GetStaticXmlFiles(string uri,string username,string password)
        {
            //Download the static requested xml files
            try
            {
                //String uri = @"ftp://" + textBoxIP.Text.Trim() + @"/Yootech/";
                //String username = ConfigurationManager.AppSettings.Get("FTPUserName");
                //String password = ConfigurationManager.AppSettings.Get("FTPPassword");

                Uri serverUri = new Uri(uri + "StockInfo.xml");
                // The serverUri parameter should start with the ftp:// scheme.
                if (serverUri.Scheme != Uri.UriSchemeFtp)
                    return false;

                // Get the object used to communicate with the server.
                using (WebClient request = new WebClient())
                {
                    // This example assumes the FTP site uses anonymous logon.
                    request.Credentials = new NetworkCredential(username, password);
                    try
                    {
                        request.DownloadFile(serverUri, "StockInfo.xml");
                        request.DownloadFile(uri + "StockList.xml", "StockList.xml");
                        //request.DownloadFile(uri + "ServerUserConfig.xml", "ServerUserConfig.xml");//YTV
                    }
                    catch (WebException ex)
                    {
                        return false;
                    }
                }
            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }
    }
}
